<?php
namespace app\html5\controller;
use app\Db2;
use app\H5AuthController;

class User extends H5AuthController{
    //编辑个人信息
    public function saveUser(){
        $user = $this->user;
        $id = $user['id'];

        if(!$id || $id == 'undefined') return rejson(302,'必填字段确实');
        // 必填字段，姓名，身份证，手机号，毕业学校，专业，医师资格证、执业证，职称证，主治项目，注册地址、多点执业地址
        $name = input('name');
        $tel = input('tel');
        $idcard = input('idcard');
        $school = input('school');
        $zhuanye = input('zhuanye');
        $yishizigezheng = input('yishizigezheng');
        $zhizheng = input('zhiyezheng');
        $zhichengzheng = input('zhichengzheng');
        $zhuzhixiangmu = input('zhuzhixiangmu');
        $address = input('address');
        $more_address = input('more_address');


        if((!$name || $name == 'undefined')
            || (!$tel || $tel == 'undefined')
            || (!$idcard || $idcard == 'undefined')
            || (!$school || $school == 'undefined')
            || (!$zhuanye || $zhuanye == 'undefined')
            || (!$yishizigezheng || $yishizigezheng == 'undefined')
            || (!$zhizheng || $zhizheng == 'undefined')
            || (!$zhichengzheng || $zhichengzheng == 'undefined')
            || (!$zhuzhixiangmu || $zhuzhixiangmu == 'undefined')
            || (!$address || $address == 'undefined')
            || (!$more_address || $more_address == 'undefined')
        ) {
            return rejson(302,'必填字段缺失');
        }

        $data = [
            'name' => $name,
            'tel' => $tel,
            'idcard' => $idcard,
            'school' => $school,
            'zhuanye' => $zhuanye,
            'yishizigezheng' => $yishizigezheng,
            'zhizheng' => $zhizheng,
            'zhichengzheng' => $zhichengzheng,
            'zhuzhixiangmu' => $zhuzhixiangmu,
            'address' => $address,
            'more_address' => $more_address,
        ];

        $num = Db2::update_data('user',[['id' => $id]],$data);

        return $num ? resjon(200,'保存成功') : rejson(0, '保存失败');
    }
    
    //获取员工详情
    public function get_user_info(){
        $user = $this->user;

        $id = input('id');

        if($id == 'undefined'){
            if($user['type']!=5) return rejson(0,'您没有管理员权限', []);
        }else{
            $id = $user['id'];
        }

        $where = ['id'=>$id];

        $res = Db2::get_data("user_doc",[$where]);

        return rejson(200,'查询成功', $res);
    }

    //获取员工列表
    public function get_user_list(){
        $user = $this->user;
        
//        if($user['type']>1) return rejson(0,'您没有管理员权限', []);

        $listnum = input('limit');
        $curpage = input('curpage');
        $status = input('status');

        $where = [];
        if ($status == 'undefined') {
            $where['status'] = 1;
        }else{
            $where['status'] = $status;
        }

        $list = Db2::get_datalist_page("user_doc",[$where],$curpage,$listnum,null,'id desc');

        return rejson(200,'查询成功', $list);
    }

//    //审核审核信息
//    public function get_user_list(){
//        $user = $this->user;
//
//        if($user['type']>1) return rejson(0,'您没有管理员权限', []);
//
//        $name = input('name');
//
//        return rejson(200,'查询成功', ['has' => true]);
//    }
    //删除人员信息
}

